<template>
    <div id="forget-moblie">
        <h2>正在重新设置密码</h2>
        <div class="explain-forget">为保证您的资料安全，<br/>请输入您注册时使用的手机号</div>
        <group>
            <x-input keyboard="number" ref="mobile01" name="mobile" is-type="china-mobile" v-model="value"  placeholder="请输入注册手机号"></x-input>
        </group>
        <div class="share" @click="next">下一步</div>
        <!-- <div class="register-other" @click="register">联系客服</div> -->
    </div>
</template>
<script>
import { XInput, Group } from 'vux'
import api from '../api'
import utils from '../utils'
export default {
  data () {
    return {
      value: ''
    }
  },
  components: {
    XInput,
    Group
  },
  created () {
    window.document.title = '设置密码'
  },
  methods: {
    next () {
      if (this.value === '') {
        this.$vux.toast.show({
          text: '请输入手机号',
          type: 'warn',
          width: '4rem'
        })
      } else if (this.$refs.mobile01.valid === false) {
        this.$vux.toast.show({
          text: '请检查手机号格式',
          type: 'warn',
          width: '4rem'
        })
      } else {
        var timeStamp = String(Number(new Date()))
        var tokenval = utils.AnonToken(timeStamp)
        api.check({
          token: tokenval,
          timestamp: timeStamp,
          mobile: this.value
        }).then(res => {
          console.log(res)
          if (res.status === '400001002') {
            this.$router.push('/passport/updatePassword?mobile=' + this.value)
          } else if (res.status === '400001001') {
            this.$vux.toast.show({
              text: '用户不存在',
              type: 'warn',
              width: '4rem'
            })
          } else {
            this.$vux.toast.show({
              text: res.message,
              type: 'warn',
              width: '4rem'
            })
          }
        })
      }
    }
  }
}
</script>
